const { Sequelize } = require("sequelize");
const path = require("path");
const sequelize = new Sequelize("zhuzhou-emergency", "root", "root_password", {
    host: "localhost",
    dialect: "mysql",
    // define: {
    //     timestamps: true,
    //     createdAt: 'created_at',
    //     updatedAt: 'updated_at',
    //     deletedAt: 'deleted_at'
    // },
    // models: [
    //     path.join(__dirname, "../models/*.model.js"),
    // ],
})

const connect = async () => {
    try {
        await sequelize.authenticate();
        // await sequelize.sync({ alter: true });
        // for (let model of Object.values(sequelize.models)) { // 同步本地数据库模型
        //     await model.sync({ alter: true }) // 没有就创建 有就比对表之间的差别 并修改
        // }
        console.log("Connection has been established successfully.");
    } catch (error) {
        console.error("Unable to connect to the database:", error);
    }
}

module.exports = { connect, sequelize }